package com.huatai.manage.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.manage.query.PageQuery;
import com.huatai.manage.query.RemoveQuery;
import com.huatai.manage.entity.TbTrialSubjectEntity;

import com.huatai.manage.query.TrialIdPageQuery;
import com.huatai.manage.query.TrialIdQuery;
import com.huatai.manage.service.TbTrialSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 试验对象;(TbTrialSubjectsManage)表控制层
 *
 * @author luoxc
 * @since 2023-03-14 14:13:39
 */
@RestController
@RequestMapping("subject")
@Api(value = "试验模型对象管理", tags = "试验模型对象管理")
public class TbTrialSubjectController {

	@Autowired
	private TbTrialSubjectService tbTrialSubjectService;

	@ApiOperationSupport(order = 1, includeParameters = {
		"pageQuery.current",
		"pageQuery.size",
		"pageQuery.data.subjectName"
	})
	@PostMapping("pageList")
	@ApiOperation(value = "分页查询数据", notes = "分页查询数据")
	public R selectAll(@RequestBody PageQuery<TbTrialSubjectEntity> pageQuery) {
		return R.data(this.tbTrialSubjectService.pageList(pageQuery));
	}

	@PostMapping("list")
	@ApiOperation(value = "查询所有数据", notes = "查询所有数据")
	public R list() {
		return R.data(this.tbTrialSubjectService.subjectList());
	}

	@PostMapping("pageByTrialId")
	@ApiOperation(value = "根据trialId分页查询数据", notes = "根据trialId分页查询数据")
	public R pageByTrialId(@RequestBody TrialIdPageQuery trialIdPageQuery) {
		return R.data(this.tbTrialSubjectService.pageByTrialId(trialIdPageQuery));
	}

	@PostMapping("listByTrialId")
	@ApiOperation(value = "根据trialId查询对象列表", notes = "根据trialId查询对象列表")
	public R listByTrialId(@ApiParam(name = "trialId", value = "试验id", required = true) @RequestParam("trialId") String trialId) {
		return R.data(this.tbTrialSubjectService.listByTrialId(trialId));
	}

	@PostMapping("getBySubjectId")
	@ApiOperation(value = "通过试验对象id查询单条数据", notes = "通过试验对象id查询单条数据")
	public R getOne(@ApiParam(name = "subjectId", value = "试验对象id", required = true) @RequestParam("subjectId") String subjectId) {
		return R.data(this.tbTrialSubjectService.getBySubjectId(subjectId));
	}

	@PostMapping("getByTrialId")
	@ApiOperation(value = "根据试验id查询（壹瞰思）", notes = "根据试验id查询（壹瞰思）")
	public R getByTrialId(@RequestBody @Valid TrialIdQuery trialIdQuery) {
		return R.data(this.tbTrialSubjectService.getByTrialId(trialIdQuery.getTrialId()));
	}

	@PostMapping("insert")
	@ApiOperation(value = "新增数据", notes = "新增数据")
	public R insert(@RequestBody @Valid TbTrialSubjectEntity tbTrialSubjectEntity) {
		return R.status(this.tbTrialSubjectService.insert(tbTrialSubjectEntity));
	}

	@PostMapping("update")
	@ApiOperation(value = "修改数据", notes = "修改数据")
	public R update(@RequestBody @Valid TbTrialSubjectEntity tbTrialSubjectEntity) {
		return R.data(this.tbTrialSubjectService.update(tbTrialSubjectEntity));
	}

	@PostMapping("removes")
	@ApiOperation(value = "删除数据", notes = "删除数据")
	public R removes(@RequestBody RemoveQuery remove) {
		return R.data(this.tbTrialSubjectService.removes(remove.getIds()));
	}

}

